#coding=utf-8

import multiprocessing
from img_tool import *

#获取页面
def get_page(url,dirList,start,end,param,channelList):
 for i in range(start,end):
  noteAddr="http://jfbra.com/web_page/forum_h5/post.html?post_id="
  noteAddr=noteAddr+str(i)
  #print noteAddr
  response = urllib.urlopen(url+str(i)).read()
  try:
    get_detail(response,dirList,param,noteAddr,channelList)
  except:
    continue
 print "get_data finished"

#入口函数
def start(start,end,count,url,dirList,param,channelList):
    process_list=[]
    index=(end-start)/count
    for i in range(count):
        process_list.append(multiprocessing.Process(target = get_page, args = (url,dirList,start+index*i,start+index*(i+1),param,channelList)))
        #print start+index*i,start+index*(i+1)
    process_list.append(multiprocessing.Process(target = get_page, args = (url,dirList,start+index*i,end+1,param,channelList)))
    #print start+index*i,end+1
    for process in process_list:
        process.start()
# 18 21 22 28 29
# http://jfbra.com/web_page/forum_h5/post.html?post_id=91267
# http://app.jfbra.com/bra_app/post/get_share_post/16569

if __name__ == "__main__":
    url="http://app.jfbra.com/bra_app/post/get_share_post/"
    channelList=[]
    for i in range(1,40):
        channelList.append(i)
    dirList=[]
    dir=u"D://final/"+str(time.time())
    for channel in channelList:
        newDir=dir+"channel"+str(channel)+"/"
        dirList.append(newDir)
    make_dirs(dirList)
    paramList=[1000,10,10]
    start(1,110000,10,url,dirList,paramList,channelList)